import com.mysql.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCTest2 {
    public static void main(String[] args) {
        //delete update
        Connection conn = null;
        Statement stam = null;
        try {
            //1.注册驱动
            DriverManager.registerDriver(new Driver());
            //2.获取连接
            conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/bjpowernode", "root", "246810");
            //3.获取数据库操作对象
            stam = conn.createStatement();
            //4.执行sql语句
            //int count = stam.executeUpdate("delete from dept where deptno = 40");
            // JDBC中的sql语句不需要提供分号结尾。
            int count = stam.executeUpdate("update dept set dname = '销售部',loc = '天津' where deptno = 50");
            System.out.println(count == 1 ? "删除成功" : "删除失败");
            //5.处理查询结果集
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            //6.释放支援
            try {
                if (stam != null) {
                    stam.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
